﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;
using System.Configuration;
using Microsoft.Practices.Unity;

namespace Web
{
    public partial class Default2 : PageBase
    {

        #region  变量
        public string mailInfo = "";
        public int usermsgcount = 0;
        public string usermsgurl = null;
        public int usertodocount = 0;
        public string usertodourl = null;

        public string TabTitle = "OCS";
        public string StringUrl = "";
        #endregion


        /// <summary>
        /// 菜单ID
        /// </summary>
        public string MenuParentID
        {
            get
            {
                if (null != Request.QueryString["id"])
                {
                    return Request.QueryString["id"];
                }
                else
                {
                    return string.Empty;
                }
            }
        }


        /// <summary>
        /// 页面标题
        /// </summary>
        public string PageTitle
        {
            get
            {
                if (null != Request.QueryString["title"])
                {
                    return Request.QueryString["title"];
                }
                else
                {
                    return string.Empty;
                }
            }
        }



        /// <summary>
        /// 用户名
        /// </summary>
        public string User_Name
        {
            get
            {
                return this.CurrentUser.User_Name;
            }
        }

        /// <summary>
        /// 用户名
        /// </summary>
        public string User_ID
        {
            get
            {
                return this.CurrentUser.User_ID;
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            SetHidenFiled();
            if (!IsPostBack)
            {
                if (PageTitle != string.Empty)
                {
                    this.Title = "档案管理系统—" + PageTitle;
                }
            }
        }

        private void GetStringParam()
        {
            String sUrl = this.Request.QueryString["ActionUrl"];
            if (sUrl != null && sUrl != "")
            {
                StringUrl = Request.ApplicationPath+ CreateActionUrl(sUrl);
            }
            //this.TabTitle = Request.QueryString["TableTitle"];
            this.TabTitle = "代办处理";
        }

        /// <summary>
        /// 设置隐藏按钮的值
        /// </summary>
        private void SetHidenFiled()
        {
            string IsRemove = Request.QueryString["remove"] != null ? Request.QueryString["remove"] : "1";
            this.IsRemoveTab.Value = IsRemove;
            //将菜单父ID存储在隐藏字段里面
            this.menuParentId.Value = MenuParentID;
            this.h_UserId.Value = this.CurrentUser.User_ID;
        }

        /// <summary>
        /// 获取用户工作信息（即时消息，代办）
        /// </summary>
        private void GetUserTodoInfo()
        {
            string userId = this.CurrentUser.User_ID;
            //usermsgcount = Instant.GetInstantMessage(userId).Tables[0].Rows.Count;
            ////usertodocount = Instant.GetComisionNotice(userId).Tables[0].Rows.Count;
            //CommissionService comission = new CommissionService();
            //string errmsg = "";
            //CommissionData[] commissonData = comission.GetCommissionData(out errmsg);
            //if (commissonData != null)
            //{
            //    usertodocount = commissonData.Length;
            //}
            //else
            //{
            //    usermsgcount = 0;
            //}
            //usermsgurl = "Views/WorkAssistant/MessageReceive.aspx";
            //usertodourl = "Views/WorkAssistant/CommissionNotice.aspx";
        }


        private void GetUserMail()
        {
            //try
            //{
            //    string userName = this.CurrentUser.Login_ID;
            //    string userPwd = this.CurrentUser.Login_Pwd;
            //    string adImitationLs = ConfigurationManager.AppSettings["SSoLogion"];
            //    string AppId = ConfigurationManager.AppSettings["EmailAppId"];
            //    POP pop = new POP("mail.cnpc.com.cn", userName, userPwd);
            //    int emailCount = pop.GetNewMailCount();
            //    mailInfo = "<a title=\"邮件" + emailCount + "封\" href=\"" + adImitationLs + "?AppId=" + AppId + "\" target=\"_blank\"><span style=\" margin-left:10px;\" >" + emailCount + "</span></a>";
            //}
            //catch (Exception ex)
            //{
            //    string scripts = "Alert('错误详细信息是:" + ex.Message + "')";
            //    mailInfo = "<a title=\"与邮箱集成失败，点击查看详细信息\" href=\"javascript:" + scripts + "\" target=\"_blank\"><span style=\" margin-left:10px;\" >0</span></a>";
            //}
        }

        /// <summary>
        /// 替换URL字符
        /// </summary>
        public string CreateActionUrl(string ActionUrl)
        {
            ActionUrl = ActionUrl.Replace("question", "?");
            ActionUrl = ActionUrl.Replace("equal", "=");
            ActionUrl = ActionUrl.Replace("with", "&");
            return ActionUrl;
        }
    }
}
